<%--
  Created by IntelliJ IDEA.
  User: dream
  Date: 14-4-4
  Time: 下午11:14
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@include file="../header.jsp"%>
<jsp:include page="../taglib.jsp"></jsp:include>
<html>
<head>
    <title></title>
</head>
<body>
<div class="easyui-layout" data-options="fit:true">
    <div data-options="region:'west',split:true,border:false" style="width:200px">
        <div style="margin-top:10px;min-height: 200px;height: 300px;">
            <div style="margin:5px 10px;">
                <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="perDept_add('1')">添加根节点</a>
            </div>
            <ul id="perDept_tree" treeMenuId="perDept_tree_menu" url="${ctx}/perDept/tree.do" class="defalut_tree"></ul>
        </div>
    </div>
    <div data-options="region:'center',border:false">
        <table id="perUser_table" class="default_table">
        </table>
        <div id="perUser_toolbar" class="default_toolbar">
            <div style="float: left">
                <a href="javascript:void(0)" class="easyui-linkbutton add_button" id="perUser_add_button"
                   iconCls="icon-add" plain="true">添加用户</a>
                <a href="javascript:void(0)" class="easyui-linkbutton remove_button" id="perUser_remove_button"
                   iconCls="icon-remove" plain="true">删除用户</a>
            </div>
            <div style="float: right;margin-left: 20px">
                <a href="javascript:void(0)" url="${ctx}/perUser/search.do" windowId="perUser_search_window"
                   class="advance_search_form_show">高级查询</a>
            </div>
            <div style="float: right;display: none;">
                <input id="perUser_search_box" class="default_search_box">

                <div class="default_search_menu">
                    <div data-options="name:'all'">全部</div>
                    <div data-options="name:'name'">名称</div>
                </div>
            </div>
            <div class="clear"></div>
        </div>
    </div>
</div>
<div id="perDept_tree_menu" class="easyui-menu" style="width:120px;">
    <div data-options="iconCls:'icon-add'" onclick="perDept_add();"><span>添加节点</span></div>
    <div data-options="iconCls:'icon-edit'" onclick="perDept_edit();"><span>编辑节点</span></div>
    <div data-options="iconCls:'icon-remove'" onclick="perDept_remove();"><span>删除节点</span></div>
</div>
<script>
    var perUser_table = $('#perUser_table');
    var perDept_tree = $('#perDept_tree');
    var perDept_tree_menu=$('#perDept_tree_menu');
    var perUser_serach_box = $('#perUser_search_box');
    $(function () {
        perDept_tree.initTree({
            onClick: function (node) {
                perUser_table.reloadGrid({nodeId: node.id});
            },
            onContextMenu: function (e, node) {
                perDept_tree.tree('select', node.target);
                perDept_tree_menu.menu('show', {
                    left: e.pageX,
                    top: e.pageY
                });
            }
        });
        perUser_table.initGrid({
            url: '${ctx}/perUser/getGridData.do',
//            fitColumns:false,
            toolbar: '#perUser_toolbar',
            searchForm: '#perUser_search_form',
            columns: [
                [
                    {field: 'ck', checkbox: true},
                    {field: 'id', title: 'id', width: 80},
                    {field: 'username', title: '登陆名', width: 100,
                        formatter: function (value, row, index) {
                            return "<a href=\"#\" onclick=\"perUser_view('" + row.id + "'" + ")\">" + row.username + "</a>";
                        }
                    },
                    {field: 'perDept.name', title: '部门', width: 100,
                        formatter: function (value, row, index) {
                            if (row.perDept == null) {
                                return '';
                            } else {
                                return row.perDept.name;
                            }
                        }
                    },
                    {field: 'operate', title: '操作', width: 100,
                        formatter: function (value, row, index) {
                            var edit_button = "<a href=\"#\" onclick=\"perUser_edit('" + row.id + "'" + ")\">" + "编辑" + "</a>";
                            var perRole_button = "<a href=\"#\" onclick=\"perUserRole_manage('" + row.id + "'" + ")\">" + "角色管理" + "</a>";
                            return edit_button+'  '+perRole_button;
                        }
                    }
                ]
            ]
        });
        perUser_serach_box.initSearchBox(perUser_table);
    })
    
    function perDept_add(data){
        var nodeId = perDept_tree.getSelectNodeId();
        var urlParams = '?bizId=' +nodeId;
        if(nodeId==null||data=='1'){
            urlParams='';
        }
        $.openWindow('${ctx}/perDept/add.do' + urlParams, 'perDept_add_window', '添加部门', 800, 400);
    }
    function perDept_edit(){
        var nodeId = perDept_tree.getSelectNodeId();
        var urlParams = '?id=' + nodeId;
        $.openWindow('${ctx}/perDept/edit.do' + urlParams, 'perDept_add_window', '编辑部门', 800, 400);
    }
    function perDept_remove(){
        perDept_tree.doDeleteNode({url: '${ctx}/perDept/delete.do',tableId:'perUser_table'});
    }

    function perUser_edit(id) {
        var urlParams = '?id=' + id;
        $.openWindow('${ctx}/perUser/edit.do' + urlParams, 'perUser_add_window', '编辑用户信息', 800, 400);
    }

    function perUser_view(id) {
        var urlParams = '?id=' + id;
        $.openWindow('${ctx}/perUser/view.do' + urlParams, 'perUser_view_window', '查看用户信息', 800, 400);
    }

    $('#perUser_add_button').click(function () {
        var nodeId = perDept_tree.getSelectNodeId();
        if (nodeId == null) {
            $.alertBox('系统提示', '请选择节点', 'info');
            return false;
        }
        var urlParams = '?bizId=' + nodeId;
        $.openWindow('${ctx}/perUser/add.do' + urlParams, 'perUser_add_window', '添加用户信息', 800, 400);
    });

    $('#perUser_remove_button').click(function () {
        perUser_table.doDelete({url: '${ctx}/perUser/delete.do'});
    });


    function perUserRole_manage(id) {
        var urlParams = '?bizId=' + id;
        $.openWindow('${ctx}/perUserRole/index.do' + urlParams, 'perUser_perUserRole_window', '用户角色管理', 600, 400);
    }
</script>
</body>
</html>